package com.ineatconseil.yougo.client.ui.main.application.tabs;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;

/**
 * @author Benjamin Barbier - Ineat Conseil
 */
public class TabsViewImpl extends Composite implements ITabsView {

	@UiTemplate("TabsUiBinder.ui.xml")
	interface TabsUiBinder extends UiBinder<HTMLPanel, TabsViewImpl> {}

	private static TabsUiBinder uiBinder = GWT.create(TabsUiBinder.class);
	@UiField TabLayoutPanel tabPanel;
	
	private Presenter presenter;

	public TabsViewImpl() {
		System.out.println("TabsViewImpl - constructor");
		// Only Since GWT v2.3
		// tabPanel.setAnimationDuration(1000);
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@Override
	public void addTab(IsWidget w, String title, Activity a) {
		
		System.out.println("TabsViewImpl - addTab");

		AcceptsOneWidget displayRegion = new SimplePanel();
		displayRegion.setWidget(w);
		
		//TODO: Passer le Bus par ici si besoin plus tard...
		a.start(displayRegion, null);
		
		tabPanel.add(w, title);
		tabPanel.selectTab(0);
		
	}

	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

}
